package com.monitor.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * controller 基类
 *
 * @author zhixingbai@creditease.cn
 */
public abstract class BaseController {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;

    @ModelAttribute
    public void init(HttpServletRequest request, HttpServletResponse response) {
        this.request = request;
        this.response = response;
        this.session = request.getSession();
    }

    /**
     * 获取请求参数值
     */
    public String getParam(String param) {
        return request.getParameter(param);
    }


    public void setSessionAttr(String name, Object value) {
        session.setAttribute(name, value);
    }

    public Object getSessionAttr(String name) {
        return session.getAttribute(name);
    }


    public void removeSessionAttr(String name) {
        session.removeAttribute(name);
    }

    public void setAttr(String name, String value) {
        request.setAttribute(name, value);
    }


}
